//
//  ChildrenViewController.m
//  XMLY
//
//  Created by 曾杰 on 15/11/4.
//  Copyright © 2015年 曾杰. All rights reserved.
//

#import "ChildrenViewController.h"
#import "YKPageView.h"
#import "ChildDetailViewController.h"
@interface ChildrenViewController ()<YKPageViewDataSource, YKPageViewDelegate>
@property (nonatomic, strong) YKPageView *mainPageView;;

@property (nonatomic, strong) NSArray *items;
@property (nonatomic, strong) ChildDetailViewController *childDetailVC;
@end

@implementation ChildrenViewController

- (NSArray *)items{
    if (_items == nil) {
        _items = @[@"最火", @"睡前故事", @"童话故事", @"儿歌总汇", @"胎教殿堂"];
    }
    return _items;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.mainPageView = [[YKPageView alloc] initWithFrame:CGRectMake(0, 70, SCREEN_WIDTH, SCREEN_HEIGHT - 70)];
    _mainPageView.delegate = self;
    _mainPageView.dataSource = self;
    _mainPageView.selectIndex = 0;
    _mainPageView.menuViewStyle = YKMenuViewStyleLine;
    [self.view addSubview:_mainPageView];
    // Do any additional setup after loading the view.
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark - page view datasource
// Menu的标题用NSArray封装，内为NSString
- (NSArray *)menuItemsForMenuViewInPageView:(YKPageView *)pageView {
    return self.items;
}

- (YKPageCell *)pageView:(YKPageView *)pageView cellForIndex:(NSInteger)index {
    static NSString *identifier = @"pageCell";
    YKPageCell *cell = [pageView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[YKPageCell alloc] initWithIdentifier:identifier];
    }
    cell.backgroundColor = [UIColor whiteColor];
    _childDetailVC = [[ChildDetailViewController alloc] initWithStyle:(UITableViewStylePlain)];
    switch (index) {
        case 0:
        {
            _childDetailVC.urlStr = @"http://mobile.ximalaya.com/mobile/discovery/v1/category/album?calcDimension=hot&categoryId=6&device=android&pageId=1&pageSize=20&status=0&tagName=";
        }
            break;
        case 1:
        {
          _childDetailVC.urlStr = @"http://mobile.ximalaya.com/mobile/discovery/v1/category/album?calcDimension=hot&categoryId=6&device=android&pageId=1&pageSize=20&status=0&tagName=%E7%9D%A1%E5%89%8D%E6%95%85%E4%BA%8B";
        }
            break;
        case 2:
        {
            _childDetailVC.urlStr = @"http://mobile.ximalaya.com/mobile/discovery/v1/category/album?calcDimension=hot&categoryId=6&device=android&pageId=1&pageSize=20&status=0&tagName=%E7%AB%A5%E8%AF%9D%E6%95%85%E4%BA%8B";
        }
            break;
        case 3:
        {
            _childDetailVC.urlStr = @"http://mobile.ximalaya.com/mobile/discovery/v1/category/album?calcDimension=hot&categoryId=6&device=android&pageId=1&pageSize=20&status=0&tagName=%E5%84%BF%E6%AD%8C%E5%A4%A7%E5%85%A8";
        }
            break;
        case 4:
        {
            _childDetailVC.urlStr = @"http://mobile.ximalaya.com/mobile/discovery/v1/category/album?calcDimension=hot&categoryId=6&device=android&pageId=1&pageSize=20&status=0&tagName=%E8%83%8E%E6%95%99%E6%AF%8D%E5%A9%B4";
        }
            break;
            
        default:
            break;
    }
    
    [cell addSubview:_childDetailVC.view];
    return cell;
}

#pragma mark Page view delegate
// 若不实现，默认红黑，为保证字体颜色渐变，请尽量选用RGBA来创建UIColor
- (UIColor *)titleColorOfMenuItemInPageView:(YKPageView *)pageView withState:(YKMenuItemTitleColorState)state {
    return [UIColor whiteColor];
}

// 若不实现,默认为30
- (CGFloat)pageView:(YKPageView *)pageView heightForMenuView:(YKMenuView *)menuView{
    return 30;
}

// 若不实现，默认为15/18
- (CGFloat)titleSizeOfMenuItemInPageView:(YKPageView *)pageView withState:(YKMenuItemTitleSizeState)state {
    switch (state) {
        case YKMenuItemTitleSizeStateNormal:
            return 15;
            break;
        case YKMenuItemTitleSizeStateSelected:
            return 18;
        default:
            break;
    }
}

// 若不实现，默认为灰色
- (UIColor *)backgroundColorOfMenuViewInPageView:(YKPageView *)pageView {
    return [UIColor lightGrayColor];
}

// MenuView 内部各个 item 的宽度，若标题过长可自行设置，默认为 60
- (CGFloat)pageView:(YKPageView *)pageView widthForMenuItemAtIndex:(NSInteger)index {
    return 100;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
